// app.js
App({
  globalData: {
    shopCarList: [],
    userInfo: {
      nickname: "Hi,游客,点击头像登录",
    },
    token: "",
  },
  onLaunch: function () {
    this.screenSize();
  },
  screenSize: function () {
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        //可视窗口宽度
        var ww = res.windowWidth;
        //可视窗口高度
        var hh = res.windowHeight;
        that.globalData.ww = ww;
        that.globalData.hh = hh;
      },
    });
  },
  bezier: function (points, times) {
    // points是起点、控制点、终点的数组
    // times是运动次数
    // 返回的是运动轨迹的数组
    var points = JSON.parse(JSON.stringify(points));
    var len = points.length;
    var bezier_points = [];
    for (var t = 0; t < times + 1; t++) {
      var tmp = [];
      for (var i = 0; i < len; i++) {
        tmp[i] = JSON.parse(JSON.stringify(points[i]));
      }
      for (var j = 1; j < len; j++) {
        for (var i = 0; i < len - j; i++) {
          tmp[i].x = (1 - t / times) * tmp[i].x + (t / times) * tmp[i + 1].x;
          tmp[i].y = (1 - t / times) * tmp[i].y + (t / times) * tmp[i + 1].y;
        }
      }
      bezier_points.push({
        x: parseInt(tmp[0].x),
        y: parseInt(tmp[0].y),
      });
    }
    console.log(bezier_points);
    return {
      bezier_points: bezier_points,
    };
  },
});
